<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt" %>

<!DOCTYPE html>
<html>
<head>
	<title>用户管理</title>

	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- 引入bootstrap -->
	<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="/css/custom.css">
	<!-- 引入JQuery  bootstrap.js-->
	<script src="/js/jquery-3.2.1.min.js"></script>
	<script src="/js/bootstrap.min.js"></script>
	<script src="/js/bootstrap-msgHint.js"></script>
</head>
<body>
	<!-- 顶栏 -->
	<jsp:include page="top.jsp"></jsp:include>
	<!-- 中间主体 -->
	<div class="container" id="content">
		<div class="row">
			<jsp:include page="menu.jsp"></jsp:include>
			<div class="col-md-10">
				<div class="panel panel-default">
				    <div class="panel-title">
						<ol class="breadcrumb breadcrumbReset">
							<li class="active">用户管理</li>
						</ol>
				    </div>
					<div class="panel-body panelBodyReset">
						<div class="searchDiv">
							<div class="col-md-7"></div>
							<form class="col-md-4" role="form" style="margin: 20px 0 10px 0;" action="/admin/searchUser" id="form1" method="post">
								<div class="input-group">
									<input type="text" class="form-control" placeholder="请输入姓名" name="findByName">
									<span class="input-group-addon btn" id="sub">搜索</span>
								</div>
							</form>
							<button class="btn btn-primary col-md-1" style="margin-top: 20px" onClick="location.href='/admin/addUser'">新增用户</button>
						</div>
						<div>${role}</div>
						<table class="table table-bordered fontSize14">
							<thead>
							<tr>
								<th>编号</th>
								<th>姓名</th>
								<th>角色</th>
								<th>电话</th>
								<th>账户金额</th>
								<th style="text-align: center;">操作</th>
							</tr>
							</thead>
							<tbody>
							<c:forEach  items="${userList}" var="item">
								<tr>
									<td>${item.userID}</td>
									<td>${item.userName}</td>
									<td>${(item.role == 1)?"admin":"user"}</td>
									<td>${item.phone}</td>
									<td>${item.balance}</td>
									<td style="text-align: center;">
										<button class="btn btn-default btn-xs btn-info" onClick="location.href='/admin/viewUser?id=${item.userID}'">查看</button>
										<button class="btn btn-default btn-xs btn-info" onClick="location.href='/admin/editUser?id=${item.userID}'">修改</button>
										<button <c:if test="${item.role == 1}"><c:out value="disabled='disabled'"/></c:if> class="btn btn-default btn-xs btn-info" onClick="location.href='/admin/userFee?id=${item.userID}'">缴费</button>
										<button <c:if test="${item.role == 1}"><c:out value="disabled='disabled'"/></c:if> class="btn btn-default btn-xs btn-info" onClick="location.href='/admin/userFeeList?id=${item.userID}'">缴费记录</button>
										<button class="btn btn-default btn-xs btn-danger btn-primary" onClick="confirmDelete(${item.userID})">删除</button>
										<!--弹出框-->
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
						<c:if test="${pagingVO != null}">
							<nav style="text-align: center">
								<ul class="pagination paginationReset">
									<li><a href="/admin/userList?page=${pagingVO.upPageNo}">&laquo;上一页</a></li>
									<li class="active"><a href="">${pagingVO.curentPageNo}</a></li>
									<c:if test="${pagingVO.curentPageNo+1 <= pagingVO.totalCount}">
										<li><a href="/admin/userList?page=${pagingVO.curentPageNo+1}">${pagingVO.curentPageNo+1}</a></li>
									</c:if>
									<c:if test="${pagingVO.curentPageNo+2 <= pagingVO.totalCount}">
										<li><a href="/admin/userList?page=${pagingVO.curentPageNo+2}">${pagingVO.curentPageNo+2}</a></li>
									</c:if>
									<c:if test="${pagingVO.curentPageNo+3 <= pagingVO.totalCount}">
										<li><a href="/admin/userList?page=${pagingVO.curentPageNo+3}">${pagingVO.curentPageNo+3}</a></li>
									</c:if>
									<c:if test="${pagingVO.curentPageNo+4 <= pagingVO.totalCount}">
										<li><a href="/admin/userList?page=${pagingVO.curentPageNo+4}">${pagingVO.curentPageNo+4}</a></li>
									</c:if>
									<li><a href="/admin/userList?page=${pagingVO.totalCount}">最后一页&raquo;</a></li>
								</ul>
							</nav>
						</c:if>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="container" id="footer">
		<div class="row">
			<div class="col-md-12"></div>
		</div>
	</div>
</body>
	<script type="text/javascript">
		$("#nav li:nth-child(2)").addClass("active");

        function confirmDelete(userId) {
			Ewin.confirm({ message: "确认要删除当前用户吗？" }).on(function (e) {
				if(!e) {
					return;
				}
				location.href='/admin/removeUser?id='+userId;
			})
        };

        $("#sub").click(function () {
            $("#form1").submit();
        });

        <c:if test="${pagingVO != null}">
			if (${pagingVO.curentPageNo} == ${pagingVO.totalCount}) {
				$(".pagination li:last-child").addClass("disabled")
			};

			if (${pagingVO.curentPageNo} == ${1}) {
				$(".pagination li:nth-child(1)").addClass("disabled")
			};
        </c:if>
	</script>
</html>